package com.lenovo.smarttraffic.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lenovo.smarttraffic.R;
import com.lenovo.smarttraffic.util.Utils;

import java.util.ArrayList;

public class UserCarRvAdapter extends RecyclerView.Adapter<UserCarRvAdapter.InitView> {

    private ArrayList<String[]> itemData;
    private View view = null;


    public UserCarRvAdapter(ArrayList<String[]> itemData) {
        this.itemData = itemData;
    }

    @NonNull
    @Override
    public InitView onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_car_info, parent, false);
        return new InitView(view);
    }

    @Override
    public void onBindViewHolder(@NonNull InitView holder, int position) {
        holder.car_number.setText(itemData.get(position)[0]);
        holder.car_number.setCompoundDrawablePadding(10);
        holder.car_number.setCompoundDrawablesWithIntrinsicBounds(null, view.getContext().getDrawable(Utils.getCarBandRes(itemData.get(position)[1])), null, null);
    }

    @Override
    public int getItemCount() {
        return itemData.size();
    }


    static class InitView extends RecyclerView.ViewHolder {
        TextView car_number;

        public InitView(View itemView) {
            super(itemView);
            car_number = itemView.findViewById(R.id.car_number);
        }
    }
}
